﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Transiteers.Models
{
    public partial class TransiteersDB
    {

        public Shift GetShift(int id)
        {
            return BaseDB.Shifts.FirstOrDefault(s => s.ID == id);
        }

        public IEnumerable<Shift> GetShiftsForTask(int taskID)
        {
            return from s in BaseDB.Shifts
                   where s.TaskID == taskID
                   select s;
        }

        public IEnumerable<Shift> GetShiftsForUser(int userID)
        {
            return from s in BaseDB.Shifts
                   join p in BaseDB.Periods
                   on s.PeriodID equals p.ID
                   where p.UserID == userID
                   select s;
        }

        public void Add(Shift shift)
        {
            BaseDB.Shifts.Add(shift);
            BaseDB.SaveChanges();
        }

        public void Remove(Shift shift)
        {
            BaseDB.Shifts.Remove(shift);
        }

    }
}